package juf.adapter;

import java.awt.Component;
import java.text.ParseException;
import java.awt.Dimension;


import juf.*;

/**	Defines common interface for of update/refresh operations between 
 * 	a component and a data source (normally a field or method-pair on an object)
 * 	while preserving a loose coupling between these classes. 
 * 
 * @author Dale Halliwell
 *
 */
public interface Adapter {

	/**Establishes a channel between an UI component and a data source described by the Property interface
	 * This should typically be called from in the constructor of implementing classes, but it could also 
	 * be used to dynamically reset the binding (cool).
	 * 
	 * @param property Property representing the data source to bind a component to
	 * @param defaultSize default size of the component (can be overridden using annotation)
	 */
	public void bind(Property property, Dimension defaultSize);
	
	/**
	 * Refreshes the component (view) from the property (model)
	 */
	public void refresh();
	
	/**
	 * Saves the property (model) from the component (view)
	 */
	public void save() throws ParseException;
	
	/**
	 * Returns true if the Adapter's data is valid according to its type
	 * @return boolean true if valid
	 */
	public boolean validateField();
	
	
	/** Displays an icon beside the adapter that shows the data was not saved because it is invalid
	 * will show until the next valid save() operation
	 */
	public void showInvalidWarning();

	/**
	 * This will be invoked by components and containers that want to add the
	 * bound component as a child, or in the AdapterFactory to set properties of the component directly 
	 * (from annotations, for example)
	 * 
	 * @return the bound component
	 */
	Component getDataComponent();
	

	/**
	 * This will be invoked to examine aspects of the Property, like the field name and annotations
	 * 
	 * @return the bound Property
	 */
	Property getProperty();
	
}
